package io.tij;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class GZIPCompress {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		
		String filePath = "file.txt";
		String gzipFilePath = "test.gz";
		
		BufferedReader in = new BufferedReader(new FileReader(filePath));
		BufferedOutputStream out = new BufferedOutputStream(
				new GZIPOutputStream(new FileOutputStream(gzipFilePath)));
		
		System.out.println("Writing file");
		int c;
		while((c = in.read()) != -1){
			out.write(c);
		}
		in.close();
		out.close();
		
		System.out.println("Reading file");
		
		in = new BufferedReader(
				new InputStreamReader(
						new GZIPInputStream(new FileInputStream(gzipFilePath))));
		String s;
		while((s = in.readLine()) != null){
			System.out.print(s);
		}
		
	}

}
